package mao.exaimnation.didi;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Totoro
 * @date 2020/9/13
 * @explain:
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int times = scanner.nextInt();
        for (int i = 0; i < times; i++) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int k = scanner.nextInt();
            ArrayList<Integer>[] adj = new ArrayList[n+1];
            for (int j = 0; j < m; j++) {
                int start = scanner.nextInt();
                int end = scanner.nextInt();
                int cost = scanner.nextInt();
                if (cost <= k){
                    if (adj[start] == null) adj[start] = new ArrayList<>();
                    if (adj[end] == null) adj[end] = new ArrayList<>();
                    adj[start].add(end);
                    adj[end].add(start);
                }
            }
            boolean[] marked = new boolean[n+1];
            dfs(adj,marked,1);
            boolean res = true;
            for (int j = 1; j <= n; j++) {
                if(!marked[j]) res=false;
            }
            if (res) System.out.println("Yes");
            else System.out.println("No");
        }
    }

    public static void dfs(ArrayList<Integer>[] adj,boolean[] marked,int cur){
       // if (marked[cur]) return;
        marked[cur] = true;
        if (adj[cur] != null){
            for (Integer i : adj[cur]) {
                if (!marked[i]){
                    dfs(adj,marked,i);
                }
            }
        }
    }
}
